package com.huijie.core.interceptor;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** 
* @ClassName: RequestInterceptor 
* @Description: 拦截器
* @author JsonY 
* @date 2017年11月28日 下午3:12:20
*/
public class RequestInterceptor extends HandlerInterceptorAdapter{
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
		long startTime=System.currentTimeMillis();
		request.setAttribute("startTime", startTime);
		return true;
	}
	
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) {
		long startTime=(long) request.getAttribute("startTime");
		long endTime=System.currentTimeMillis();
		System.out.println("本次请求处理的时间为："+(endTime-startTime)+"ms");
		request.setAttribute("handlingTime",endTime-startTime);
	}
}
